package com.jack.leetcode.每日一题;

/*** 
 * @author zhangjie
 * @date 2020/4/18 16:19
 */
public class 盛最多水的容器 {

    public static void main(String[] args) {
        int[] height = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(height));
    }

    public static int maxArea(int[] height) {
        int n = height.length;
        int left = 0;
        int right = n-1;
        int maxHeight = height[left]<height[right]?height[left]:height[right];
        int max = maxHeight*(right-left);
        while(left<right){
            if(height[left]<height[right]){
                left++;
                maxHeight = height[left]<height[right]?height[left]:height[right];
                max = Math.max(maxHeight*(right-left),max);
            }else{
                right--;
                maxHeight = height[left]<height[right]?height[left]:height[right];
                max = Math.max(maxHeight*(right-left),max);
            }
        }
        return max;
    }
}
